// pages/home/report/report.js
const app = getApp()
var util = require("../../../utils/util.js")
const db = wx.cloud.database()
const _ = db.command
const reportDB=db.collection('reportData') 
var  selectedType=-1
var reportType = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    reportArray:[{id:1,content:"垃圾营销"}
    ,{id:2,content:"内容抄袭"},{id:3,content:"诈骗信息"},{id:4,content:"人身攻击"},
    {id:5,content:"不实信息"},{id:6,content:"违法信息"},{id:7,content:"有害信息"},{id:8,content:"其他"}],
    report_opacity:[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],
    // selectedType:-1,
    input_Hidden:true,
    // reportType:'',
    publishid:''
  },

  lighttheReport:function(e){
    let that = this
    console.log("点击的按钮id",e.currentTarget.id)
    let id = Number(e.currentTarget.id)
    let _length = that.data.report_opacity.length
    if(that.data.report_opacity[id-1]==1){

    }else{
      for(var i=1;i<=_length;i++){
        if(i==id){
          that.data.report_opacity[i-1] = 1
        }else{
        that.data.report_opacity[i-1] = 0.5
        }
      }
    }
    if(id == 8){
      that.setData({
        input_Hidden:false,
        // reportType:''
      })
      reportType = ''
    }else{
      that.setData({
        input_Hidden:true,
        // reportType:that.data.reportArray[id-1].content
      })
      reportType = that.data.reportArray[id-1].content
    }
    that.setData({
      report_opacity:that.data.report_opacity,
      // selectedType:id
    })
    selectedType = id
    console.log(that.data.report_opacity,selectedType,reportType)
  },

  getinputType:function(e){
      console.log(e.detail.value)
      // this.setData({
      //   reportType:e.detail.value
      // })
      reportType = e.detail.value
  },
  clickBtnSure:function(){
    let that = this
    // let id = that.data.selectedType
    // let id = selectedType
    // let type = that.data.reportType
    // let type = reportType
    console.log("点击确定后的结果：",selectedType,reportType)
    if (reportType == "") {
        wx.showToast({
          title: '你还没有输入内容',
          icon: "none",
          duration: 2000,
        })
    }
    else{
        reportDB.add({
          data: {
            Reporter:app.globalData.userOpenid,
            ReportDate:util.formatTime(new Date()),
            publishID:that.data.publishid,
            beReportReason:reportType,
          },
          success: function(res) {
            console.log(res)
            wx.showToast({
              title: '举报成功，等待审核',
              icon:'none',
              duration: 5000,
              success: function () {
                wx.navigateBack({
                })
              }
            })
          }
        })
  }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log(options.publishID)
      this.setData({
        publishid:options.publishID
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})